package com.asdhawaii.otello.board;

/**
 * A move on the Otello board.
 * 
 * @author Branden Ogata
 *
 */

public class Move
{
  /**
   * The row coordinate of this Move.
   * 
   */
  private int row;
  
  /**
   * The column coordinate of this Move.
   * 
   */
  private int column;
  
  /**
   * Creates a new Move.
   * 
   * @param row The int equal to the row coordinate of the new Move.
   * @param column The int equal to the column coordinate of the new Move.
   * 
   */
  
  public Move(int row, int column)
  {
    this.row = row;
    this.column = column;
  }
  
  /**
   * Returns the row coordinate of this Move.
   *
   * @return row The int containing the row coordinate of this Move.
   *
   */
  
  public int getRow()
  {
    return this.row;
  }
  
  /**
   * Returns the column coordinate of this Move.
   *
   * @return column The int containing the column coordinate of this Move.
   *
   */
  
  public int getColumn()
  {
    return this.column;
  }
  
  /**
   * Indicates whether the given move exists on the given board.
   * 
   * @param board The Square[][] representing the Otello board.
   * @param move The Move to examine.
   * 
   * @return A boolean that is true if the move is on the board,
   *                           false otherwise.
   *                           
   */
  
  public static boolean onBoard(Square[][] board, Move move)
  {
    return (0 <= move.getRow()) && (move.getRow() < board.length) && 
           (0 <= move.getColumn()) && (move.getColumn() < board[move.getRow()].length);
  }
  
  /**
   * Compares this Move to another Object for equality.
   * 
   * @param obj The Object to compare this Move to.
   * 
   * @return isEqual A boolean that is true if this Move is equal to the parameter,
   *                                   false otherwise.
   * 
   */
  
  @Override
  public boolean equals(Object obj)
  {
    boolean isEqual = false;
    
    if (this == obj)
    {
      isEqual = true;
    }
    else if (obj instanceof Move)
    {
      Move temp = (Move) obj;
      
      isEqual = (this.column == temp.getColumn()) && (this.row == temp.getRow());
    }
    
    return isEqual;
  }
  
  /**
   * Returns the hash code for this Move instance.
   * 
   * @return result An int equal to the hash code for this Move.
   * 
   */
  
  @Override
  public int hashCode()
  {
    int result = 17;
    int combination = this.column + this.row;
    result = 11 * result + combination;
    
    return result;
  }
  
  /**
   * Returns a String representation of this Move.
   * 
   * @return A String containing the coordinates of this Move.
   *    
   */
  @Override
  public String toString()
  {
    return "Move [row=" + row + ", column=" + column + "]";
  }
}
